package com.wjk.kylin.core.constant;

import lombok.Getter;
import org.springframework.lang.Nullable;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wangjkui
 * @description 枚举类
 * @date 2020/1/21
 */
public class CommonConstant {

    /*删除状态*/
    @Getter
    public enum DelFlagConstant {
        OK("0", "正常"), DISABLE("1", "删除");

        private String code;
        private String msg;

        DelFlagConstant(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }

    /*数据状态*/
    @Getter
    public enum DataStatus {
        OK("0", "正常"), DISABLE("1", "停用");

        private final String code;
        private final String msg;

        DataStatus(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }

    /**
     * 请求方式
     */
    public enum HttpMethod {
        GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;

        private static final Map<String, HttpMethod> mappings = new HashMap<>(16);

        static {
            for (HttpMethod httpMethod : values()) {
                mappings.put(httpMethod.name(), httpMethod);
            }
        }

        @Nullable
        public static HttpMethod resolve(@Nullable String method) {
            return (method != null ? mappings.get(method) : null);
        }

        public boolean matches(String method) {
            return (this == resolve(method));
        }
    }

    /**
     * 操作状态
     */
    @Getter
    public enum BusinessStatus {

        SUCCESS("0", "成功"),
        FAIL("1", "失败");

        private String code;
        private String msg;

        BusinessStatus(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }

    /**
     * 系统开关
     */
    @Getter
    public enum NormalDisable {

        SUCCESS("0", "成功"),
        FAIL("1", "失败");

        private String code;
        private String msg;

        NormalDisable(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }

    /**
     * 业务操作类型
     */
    @Getter
    public enum BusinessType {
        OTHER("0","其它"),
        LIST("1","列表"),
        GET("2","详情"),
        INSERT("3","新增"),
        UPDATE("4","修改"),
        DELETE("5","删除"),
        GRANT("6","授权"),
        EXPORT("7","导出"),
        IMPORT("8","导入"),
        FORCE("9","强退"),
        CODE("10","生成代码"),
        CLEAN("11","清空数据");

        private String code;
        private String msg;

        BusinessType(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }

    }


}
